package com.ht.demo.admin.controller.system;

import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.appexception.ResultData;
import com.ht.demo.common.enums.OperateTypeEnum;
import com.ht.demo.common.page.PageBO;
import com.ht.demo.common.pojo.bo.system.SysRoleBO;
import com.ht.demo.common.pojo.qto.system.SysRoleQTO;
import com.ht.demo.service.annotation.LoggerInfo;
import com.ht.demo.service.annotation.Permission;
import com.ht.demo.service.manager.system.SysRoleManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("${basePath}")
public class SysRoleController {

    @Resource
    private SysRoleManager sysRoleManager;

    @GetMapping("/findRoleForPage")
    public ResultData<PageBO<SysRoleBO>> findRoleForPage(SysRoleQTO qto) throws AppException {
        return new ResultData<>(sysRoleManager.findRoleForPage(qto));
    }

    @GetMapping("/findRoleById")
    public ResultData<SysRoleBO> findRoleById(Long sysRoleId) throws AppException {
        return new ResultData<>(sysRoleManager.findRoleById(sysRoleId));
    }

    @Permission(permissionId = "system:role:add", desc = "新增角色")
    @LoggerInfo(title = "角色管理", operateType = OperateTypeEnum.INSERT)
    @PostMapping("/system/insertRole")
    public ResultData<SysRoleBO> insertRole(@RequestBody SysRoleBO roleBO) throws AppException {
        return new ResultData<>(sysRoleManager.insertRole(roleBO));
    }

    @Permission(permissionId = "system:role:edit", desc = "修改角色")
    @LoggerInfo(title = "角色管理", operateType = OperateTypeEnum.UPDATE)
    @PostMapping("/system/updateRole")
    public ResultData<Boolean> updateRole(@RequestBody SysRoleBO roleBO) throws AppException {
        return new ResultData<>(sysRoleManager.updateRole(roleBO));
    }

    @Permission(permissionId = "system:role:edit", desc = "修改角色状态")
    @LoggerInfo(title = "角色管理", operateType = OperateTypeEnum.UPDATE)
    @PutMapping("/system/role/changeStatus")
    public ResultData<Boolean> updateRoleStatus(@RequestBody SysRoleBO roleBO) throws AppException {
        return new ResultData<>(sysRoleManager.updateRoleStatus(roleBO));
    }

    @Permission(permissionId = "system:role:remove", desc = "删除角色")
    @LoggerInfo(title = "角色管理", operateType = OperateTypeEnum.DELETE)
    @DeleteMapping("/system/role/{sysRoleIds}")
    public ResultData<Boolean> delRoleByIds(@PathVariable Long[] sysRoleIds) throws AppException {
        return new ResultData<>(sysRoleManager.delRoleByIds(sysRoleIds));
    }



}
